<%@ page import="com.my.Customer" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

<h4>c:redirect--->使当前jsp页面重定向到指定的页面。当前JSP页面转发到指定页面可以使用<%--<jsp:forward page="/test.jsp/>"--%></h4>
<c:redirect url="test.jsp"/>
<br/><br/>


<h4>c:import--->可以包含任何页面到当前页面</h4>
<c:import url="http://www.baidu.com"/>
<br/><br/>


<h4>c:forEach:可以对数组，Collection，Map进行遍历</h4>
<c:forEach var="i" begin="1" end="10" step="3">
    ${i} ---
</c:forEach>
<br/>

<%
    List<Customer> customerList = new ArrayList<Customer>();
    customerList.add(new Customer(1, "AAA"));
    customerList.add(new Customer(2, "BBB"));
    customerList.add(new Customer(3, "CCC"));
    customerList.add(new Customer(4, "DDD"));
    customerList.add(new Customer(5, "EEE"));

    request.setAttribute("customerList", customerList);
%>
<c:forEach items="${requestScope.customerList}" var="cust" varStatus="status">
    ${status.index},${status.count},${status.first},${status.last}:o${cust.id}:${cust.name}<br>
</c:forEach>

<%-- 遍历Map --%>
<%
    Map<String, Customer> customerMap = new HashMap<String, Customer>();
    customerMap.put("a", new Customer(1, "AAA"));
    customerMap.put("b", new Customer(1, "DDD"));
    customerMap.put("c", new Customer(1, "CCC"));
    customerMap.put("d", new Customer(1, "DDD"));
    customerMap.put("e", new Customer(1, "EEE"));
    customerMap.put("f", new Customer(1, "FFF"));

    request.setAttribute("customerMap", customerMap);
%>
<br/>
<c:forEach items="${requestScope.customerMap}" var="cust">
    ${cust.key}--${cust.value.id}---${cust.value.name}<br/>
</c:forEach>
<br/><br/>


<h4>c:choose, c:when, c:otherwise: 可以实现if...else if...else if...else的效果，但较为麻烦</h4>
<c:choose>
    <c:when test="${param.age > 60}">
        老年
    </c:when>
    <c:when test="${param.age > 40}">
        中年
    </c:when>
    <c:when test="${param.age > 18}">
        青年
    </c:when>
    <c:otherwise>
        未成年
    </c:otherwise>
</c:choose>
<br/><br/>


<h4>c:if--->没有else,但可以吧判断的结果储存起来，以备之后使用</h4>
<c:set value="20" scope="request" var="age"/>
<c:if test="${requestScope.age > 18}">成年了！</c:if>
<c:if test="${param.age > 18}" var="isAdult" scope="request"/>
isAdult:<c:out value="${requestScope.isAdult}"/>
<br/><br/>


<h4>c:remove--->移除指定域对象的指定属性值</h4>
<c:set var="date" value="2017-07-11" scope="session"/>
date:old---${sessionScope.date}
<br/>
<c:remove var="date" scope="session"/>
date:after---${sessionScope.date}
<br/><br/>


<h4>c:set--->可以为域对象属性赋值，其中value属性支持EL表达式；还可以为域对象中的JavaBean的属性赋值，target，value都支持EL表达式</h4>
<%-- scope:在...范围内 --%>
<c:set var="name" value="dearHaoGeGe" scope="page"/>
name:${pageScope.name}
<br/><br/>
<c:set var="subject" value="${param.subject}" scope="session"/>
subject:${sessionScope.subject}
<br/><br/>
<%
    Customer customer = new Customer();
    customer.setId(1001);
    request.setAttribute("customer", customer);
%>
ID：${requestScope.customer.id}
<br/>
<c:set target="${requestScope.customer}" property="id" value="${param.id}"/>
ID：${requestScope.customer.id}
<br/><br/>


<h4>c:out--->可以对特殊字符进行转换</h4>
<%
    request.setAttribute("book", "<<java>>");
%>
book:${requestScope.book}
<br/><br/>
book:<c:out value="${requestScope.book}"/>
</body>
</html>
